package com.googlecode.maratische.google.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.googlecode.maratische.google.dao.LabelDao;
import com.googlecode.maratische.google.model.Label;

public class LabelDaoImpl extends BaseDaoImpl<Label> implements LabelDao {

	public LabelDaoImpl(Connection conn) {
		super(conn);
	}

	@Override
	public Label createByRow(ResultSet rs) throws SQLException {
		Label label = new Label();
		label.setId(rs.getInt("ID"));
		label.setType(rs.getString("TYPE"));
		label.setComment(rs.getString("COMMENT"));
		label.setFileSaved(rs.getString("FILE_SAVED"));
		return label;
	}

	@Override
	protected String generateInsertSql() {
		return "insert into "+getTableName()+" (TYPE, COMMENT, FILE_SAVED) values (?,?,?)";
	}

	@Override
	protected String generateUpdateSql() {
		return "update "+getTableName()+" set TYPE = ?,COMMENT = ?, FILE_SAVED = ? "+
		" where ID = ? ";
	}

	@Override
	protected String getTableName() {
		return "LABEL";
	}

	@Override
	protected PreparedStatement putInsertPrepareStatement(PreparedStatement pStat, Label status) throws SQLException {
		pStat.setString(1, status.getType());
		pStat.setString(2, status.getComment());
		pStat.setString(3, status.getFileSaved());
		return pStat;
	}
	
	@Override
	protected PreparedStatement putUpdatePrepareStatement(PreparedStatement pStat, Label status) throws SQLException {
		pStat = putInsertPrepareStatement(pStat, status);
		pStat.setInt(4, status.getId());
		return pStat;
	}
}
